package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.KfnProjectVo;
import com.ruoyi.system.domain.bo.KfnProjectBo;
import com.ruoyi.system.service.IKfnProjectService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * KFN项目管理
 *
 * @author Panda
 * @date 2023-12-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/project")
public class KfnProjectController extends BaseController {

    private final IKfnProjectService iKfnProjectService;

    /**
     * 查询KFN项目管理列表
     */
    @SaCheckPermission("system:project:list")
    @GetMapping("/list")
    public TableDataInfo<KfnProjectVo> list(KfnProjectBo bo, PageQuery pageQuery) {
        return iKfnProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出KFN项目管理列表
     */
    @SaCheckPermission("system:project:export")
    @Log(title = "KFN项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(KfnProjectBo bo, HttpServletResponse response) {
        List<KfnProjectVo> list = iKfnProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "KFN项目管理", KfnProjectVo.class, response);
    }

    /**
     * 获取KFN项目管理详细信息
     *
     * @param projectId 主键
     */
    @SaCheckPermission("system:project:query")
    @GetMapping("/{projectId}")
    public R<KfnProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String projectId) {
        return R.ok(iKfnProjectService.queryById(projectId));
    }

    /**
     * 新增KFN项目管理
     */
    @SaCheckPermission("system:project:add")
    @Log(title = "KFN项目管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KfnProjectBo bo) {
        return toAjax(iKfnProjectService.insertByBo(bo));
    }

    /**
     * 修改KFN项目管理
     */
    @SaCheckPermission("system:project:edit")
    @Log(title = "KFN项目管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KfnProjectBo bo) {
        return toAjax(iKfnProjectService.updateByBo(bo));
    }

    /**
     * 删除KFN项目管理
     *
     * @param projectIds 主键串
     */
    @SaCheckPermission("system:project:remove")
    @Log(title = "KFN项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] projectIds) {
        return toAjax(iKfnProjectService.deleteWithValidByIds(Arrays.asList(projectIds), true));
    }
}
